# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=seatd
pkgver=0.9.1
pkgrel=0
pkgdesc="Minimal seat management daemon"
url="https://sr.ht/~kennylevinsen/seatd/"
license="MIT"
arch="all"
options="suid"  # needed for seatd-launch
pkggroups="seat"
install="$pkgname.pre-install $pkgname.post-install $pkgname.post-upgrade"
makedepends="meson scdoc elogind-dev linux-headers"
subpackages="libseat:libs libseat-dev $pkgname-launch $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://git.sr.ht/~kennylevinsen/seatd/archive/$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"

# secfixes:
#   0.6.2-r0:
#     - CVE-2021-41387

build() {
	if [ "$CARCH" = 'ppc64le' ]; then
		# https://todo.sr.ht/~kennylevinsen/seatd/10
		# https://www.openwall.com/lists/musl/2020/01/20/3
		export CFLAGS="$CFLAGS -Wno-error=overflow"
	fi

	abuild-meson \
		-Dlibseat-logind=elogind \
		-Dman-pages=enabled \
		. output

	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	chmod u+s "$pkgdir"/usr/bin/seatd-launch

	install -Dm755 "$srcdir"/seatd.initd "$pkgdir"/etc/init.d/seatd
	install -Dm644 "$srcdir"/seatd.confd "$pkgdir"/etc/conf.d/seatd
}

libs() {
	default_libs
	pkgdesc="Universal seat management library"
}

dev() {
	default_dev
	pkgdesc="Universal seat management library (development files)"
}

launch() {
	pkgdesc="Command to start a process with its own seatd instance (SUID binary)"
	depends="$pkgname"

	amove usr/bin/seatd-launch
}

sha512sums="
15d24a6646fa82a2bcc21d2a99693e1c54e71b9da24a0ba5c847a72c53d803410cbcee31fc847fef468b18d941d9685391bebf745819d4b24d056cd67e08c3fb  seatd-0.9.1.tar.gz
1643c291a9b6fcfb95c2b70c345d49f4575e08f12bab2fd00924f4f31eadbb068ac9fb7dcd497daa3b810baf76ced70bb7815d268c09ceabfaa0df1cd3e5280e  seatd.initd
1ee755b462455fb20ee2f56b8d1a0f3a26eb9aed34eb6126e322243f9288b23577aff40e5a2c02449f349282af79eafd232b9e77cd196daa92ee8a9fcae2ec16  seatd.confd
"
